package cn.hy;


import cn.hy.plugin.MyPlugin;
import cn.hy.plugin.MyService3;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.plugin.core.config.EnablePluginRegistries;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Optional;

@SpringBootApplication
@EnablePluginRegistries({MyPlugin.class})
public class App implements CommandLineRunner {
    public static void main(String[] args)  {
        SpringApplication.run(App.class,args);
    }

    @Resource
    private PluginRegistry<MyPlugin,String> pluginRegistry;

    @Override
    public void run(String... args) throws Exception {
        PluginRegistry<MyPlugin, String> customerPluginRegistry = PluginRegistry.of(new MyService3());

        //  Optional<MyPlugin> pluginFor = customerPluginRegistry.getPluginFor("3");

        Optional<MyPlugin> optionalMyPlugin = pluginRegistry.getPluginFor("1");
        if (optionalMyPlugin.isPresent()) {
            String[] handle = optionalMyPlugin.get().handle("spring#java");
            System.err.println("handle = " + Arrays.toString(handle));
        }
    }
}